<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        let arr1 = [1,2,3,4,5,6,78,8];
        let arr2 = [1,2,4,5,777,98];

        // 并集
        let arr3 = arr1.concat(arr2);
        console.log(arr3);
        let arr4 = [...arr1, ...arr2];
        console.log(arr4);
        let s1 = new Set(arr4);
        console.log([...s1]);

        // 交集 has方法判断是否存在
        let s2 = new Set(arr1);
        let s3 = new Set(arr2);
        let arrJiao = []
        s2.forEach(item => {
            if(s3.has(item)) {
                arrJiao.push(item)
            }
        })
        console.log('arrJiao:', arrJiao);

        // 差集[3,777,98,78,8,6]
        let arrCha1 = [];
        let arrCha2 = [];
        s2.forEach(item => {
            if(!s3.has(item)) {
                arrCha1.push(item)
            }
        })
        console.log(arrCha1);
        s3.forEach(item => {
            if(!s2.has(item)) {
                arrCha2.push(item)
            }
        })
        console.log(arrCha2);
        // 以不同的数组为基准，获取的差集结果不同


        // 遍历数组来完成
        let arrJiaoA = [];
        arrJiaoA = arr1.filter(item => {
            return arr2.includes(item)
        })
        console.log('arrJiaoA:',arrJiaoA);
    </script>
</body>
</html>